package org.hitchhike.core.repository;

import java.util.List;
import java.util.Set;

import org.hitchhike.common.repository.BaseRepository;
import org.hitchhike.core.domain.Order;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface OrderRepository
    extends BaseRepository<Order, Long>, JpaSpecificationExecutor<Order> {

  List<Order> findByOrderType(@Param("orderType") int orderType);

  Page<Order> findPageByOrderStateAndUserId(Pageable pageable, @Param("orderState") int orderState,
      @Param("userId") Long id);

  Page<Order> findPageByOrderTypeAndOrderState(Pageable pageable, @Param("orderType") int orderType,
      @Param("orderState") int orderState);

  @Query("select o from Order o where o.user.id = :id and orderState in(:orderState)")
  Page<Order> findByUserId(@Param("id") Long userId, @Param("orderState") Set<Integer> orderStates,
      Pageable pageable);

}
